package com.tencent.liteav.demo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tencent.liteav.demo.common.widget.SplashScreen;
import com.tencent.liteav.demo.liveplayer.ui.LivePlayerEntranceActivity;
import com.tencent.liteav.demo.livepusher.camerapush.ui.CameraPushEntranceActivity;

import static com.tencent.liteav.demo.livepusher.camerapush.ui.view.PusherVideoQualityFragment.SP_KEY_VIDEO_IS_FRONT;
import static com.tencent.liteav.demo.livepusher.camerapush.ui.view.PusherVideoQualityFragment.SP_KEY_VIDEO_QUALITY;
import static com.tencent.liteav.demo.livepusher.camerapush.ui.view.PusherVideoQualityFragment.SP_NAME;

public class LiveMainActivity extends Activity {

    private TextView tv_video_config;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SplashScreen.show(this, 2000);

        setContentView(R.layout.activity_live_main);
        LinearLayout ll_live_push = findViewById(R.id.ll_live_push);
        LinearLayout ll_live_method = findViewById(R.id.ll_live_method);
        tv_video_config = findViewById(R.id.tv_video_config);


        ll_live_push.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LiveMainActivity.this, LivePushActivity.class));
            }
        });
        ll_live_method.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LiveMainActivity.this, LiveMethodActivity.class));
            }
        });
        findViewById(R.id.tv_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LiveMainActivity.this, CameraPushEntranceActivity.class));
            }
        });
        findViewById(R.id.tv_play).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(LiveMainActivity.this, LivePlayerEntranceActivity.class));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        SharedPreferences s = getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        boolean isFront = s.getBoolean(SP_KEY_VIDEO_IS_FRONT, false);
        int mQualityIndex = s.getInt(SP_KEY_VIDEO_QUALITY, 1);

        StringBuilder sb = new StringBuilder("横屏，");
        sb.append(isFront ? "前" : "后").append("置摄像头，");
        String q = "";
        if (mQualityIndex == 0) {
            q = "蓝光";
        } else if (mQualityIndex == 1) {
            q = "超清";
        } else if (mQualityIndex == 2) {
            q = "高清";
        } else if (mQualityIndex == 3) {
            q = "标清";
        }
        sb.append(q);
        tv_video_config.setText(sb.toString());
    }
}
